package com.zerox.interceptor;

import com.zerox.pojo.SysUser;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @auth 吴志勇
 * @date 2022/11/16 15:48
 */
public class SysIntercetor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 是否登录
        SysUser user = (SysUser)request.getSession().getAttribute("loginUser");

        if (user == null){
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("请先登录");
            return false;
        }
        return true;
    }
}
